<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page import="com.cap.bts.framework.usermgnt.constant.EmployeeStatus"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>短信推送设定</title>
<%@include file="../include/include.jsp"%>
<link rel="stylesheet" type="text/css" href="${csspath }/public.css" />
<script type="text/javascript" src="${jspath}/jquery/jquery-2.1.3.js"></script>
<link rel="stylesheet" type="text/css"
	href="${bootstrapPath}/css/bootstrap.css" />
<script type="text/javascript" src="${bootstrapPath}/js/bootstrap.js"></script>
<script type="text/javascript" src="${layerPath }/layer.js"></script>
</head>

<script type="text/javascript">
	$(function() {
		$("#submitSetting").click(function(){
			
			var remindDefaultQuantity=$("#remindDefaultQuantity").val();
			var remindDays=$("#remindDays").val();
			var afterRemindDays=$("#afterRemindDays").val();
			var reg=/^[0-9]+$/;
			if ((!reg.test(remindDefaultQuantity))||(parseInt(remindDefaultQuantity)==0)){
				jAlert('门店短信月初始短信推送数必须为正整数！', '提示');
				return false;
			} 
			
			if ((!reg.test(remindDays))||(parseInt(remindDays)==0)){
				jAlert("距离建议推送日天数必须为正整数！","提示");
				return false;
			}
			
			if ((!reg.test(afterRemindDays))||(parseInt(afterRemindDays)==0)){
				jAlert("超过建议推送日天数必须为正整数！","提示");
				return false;
			}
			
			$("#form").attr("action","${webcontext}/crmdp/dealer/remind/saveRemindSetting");
			$("#form").submit();
		})
	});
	function deleteMsgPackage(id){
		$.ajax({
			url : '${webcontext}/crmdp/dealer/remind/deleteMsgPackage?id='+id,
			type : 'post',
			data : $('form').serialize(),
			success : function(data) {
				if (!data.result) {
					jAlert(data.errorMsg);
				} else {
						jAlert("删除成功！", "提示",function(){
							window.location.href="${webcontext}/crmdp/dealer/remind/toRemindSetting";
						})
								
				}
			},
			error : function(msg) {
				alert(msg);
			}
		})
	}
	
	function modifyMsgPackage(id){
		layer
		.open({
			type : 2,
			offset : [
					'10px',
					'25%' ],
			area : [
					'450px',
					'300px' ],
			scrollbar : false,
			title : '短信包信息',
			content : '${webcontext}/crmdp/dealer/remind/modifyMsgPackage?id='+id,
			end : function() {
			}
		});
	}
	
	function addMsgPackage(id){
		layer
		.open({
			type : 2,
			offset : [
					'10px',
					'25%' ],
			area : [
					'450px',
					'300px' ],
			scrollbar : false,
			title : '短信包信息',
			content : '${webcontext}/crmdp/dealer/remind/addMsgPackage',
			end : function() {
			}
		});
	}
</script>
<style type="text/css">
.checkbox-li {
	display: inline-block;
	width: 100px;
}
</style>
<body>
	<div id="content">
		<form id="form" class="" action="${webcontext}/crmdp/dealer/remind/toRemindSetting" method="post">
			<div class="form-group" >
				<label for="remindDefaultQuantity">门店短信月初始短信推送数</label> <input
					id="remindDefaultQuantity" name="codeInfos[0].value"
					class="form-control input-sm" style="width: 200px;"
					value="${remindDefaultQuantity}">
					<input type="hidden" name="codeInfos[0].id" value="${remindDefaultQuantityId}">
			</div>
			<div class="form-group">
				<label for="remindDays">距离建议推送日天数</label> <input id="remindDays"
					name="codeInfos[1].value" class="form-control input-sm"
					style="width: 200px;" value="${remindDays}">
					<input type="hidden" name="codeInfos[1].id" value="${remindDaysId}">
			</div>
			<div class="form-group">
				<label for="afterRemindDays">超过建议推送日天数</label> <input
					id="afterRemindDays" name="codeInfos[2].value"
					class="form-control input-sm" style="width: 200px;"
					value="${afterRemindDays}">
					<input type="hidden" name="codeInfos[2].id" value="${afterRemindDaysId}">
			</div>
			<div class="form-group">
				<label for="afterRemindDays">推送项目设定(是否启用)</label>
			</div>
			<div class="form-group">
				<div class="checkbox "
					style="width: 400px; height: 80px; display: inline-block; margin-left: 100px">
					<ul>
						<core:forEach items="${servicTypeList}" var="serviceTypeList"
							varStatus="status">
							<li class="checkbox-li"><input servicetype="servicetype"
								name="serviceTypeDto[${status.index}].serviceFlag" type="checkbox"
								<core:if test="${serviceTypeList.isDeleted eq 0}">checked</core:if>>
								<input name="serviceTypeDto[${status.index}].code" type="hidden"
								value="${serviceTypeList.code }"> <input
								name="serviceTypeDto[${status.index}].value" type="hidden"
								value="${serviceTypeList.value }">
								<input
								name="serviceTypeDto[${status.index}].id" type="hidden"
								value="${serviceTypeList.id }">
								${serviceTypeList.value}</li>
							<core:if test="${status.index eq 4 }">
								</br>
							</core:if>
						</core:forEach>
					</ul>
				</div>
			</div>
			
			<div style="text-align: center;">
				<button type="button" id="submitSetting" class="btn btn-success">
					&nbsp;确&nbsp;&nbsp;定&nbsp;
				</button>
			</div>
			<div class="form-group">
				<label for="afterRemindDays">短信包定义</label> <a
					href="javascript:void(0)" onClick="addMsgPackage()">添加</a>
				<table id="table" class="table " style="font-size: 85%">
					<thead>
						<tr>
							<th>短信包名称</th>
							<th>数量</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody>
						<core:forEach items="${msgPackageList}" var='msgPackageList'
							varStatus="status">
							<tr>
								<td>${msgPackageList.value}</td>
								<td>${msgPackageList.code}</td>
								<td><a href="javascript:void(0)"
									onClick="modifyMsgPackage(${msgPackageList.id})">修改</a> <a
									href="javascript:void(0)"
									onClick="deleteMsgPackage(${msgPackageList.id})">删除</a></td>
							</tr>
						</core:forEach>
					</tbody>
				</table>
			</div>
		</form>
	</div>
</body>
</html>